package com.esiran.payadmin.entity;

import com.google.gson.Gson;

public class Resp<T> {
    private int code;
    private String msg;
    private T data;
    private Resp(){

    }
    public static <T> Resp<T> create(int code, T data, String msg){
        Resp<T> resp = new Resp<>();
        resp.setCode(code);
        resp.setData(data);
        resp.setMsg(msg);
        return resp;
    }
    public static <T> Resp<T> create(int code,T data){
        return create(code,data,null);
    }
    public static <T> Resp<T> create(T data){
        return create(0,data);
    }
    public static <T> Resp<T> empty(){
        return create(0,null);
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public String toJson(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}

